#ifndef CPROFILE_H
#define CPROFILE_H

#include <QObject>

#include "cauthinfo.h"
#include "cmessage.h"
#include "contactinfo.h"
#include "iprofile.h"

class ContactsModel;

class CProfile : public QObject
{
    Q_OBJECT
public:
    enum State {NotConnected, Connecting, Connected, Authorizing, Authorized, LoadingContacts, ContactsLoaded};
    enum Error {NoError, OtherError, SocketError, ConnectionError, AuthorizationError};

    explicit CProfile(const CAuthInfo &authInfo, IProfile *parent = 0);
    virtual ~CProfile() {}    

    QString networkId() const;
    CAuthInfo authInfo() const;

    State state() const;    
    Error error() const;

    ContactsModel * contactsModel() const;

    virtual void sendMessage(const QString &message, const ContactInfo &to) = 0;

    virtual ContactInfo profileInfo() const {return m_profileInfo;}
    virtual ContactInfo resolveUid(const QString &uid) const = 0;

    virtual void connectToNetwork() = 0;
    virtual void disconnectFromNetwork() = 0;

signals:
    void profileInfoChanged();
    void stateChanged(CProfile::State state);
    void errorChanged(CProfile::Error error);

    void messageReceived(const CMessage &message);

protected:
    void setState(State state);
    void setError(Error error);

    CAuthInfo m_authInfo;
    ContactInfo m_profileInfo;
    ContactsModel * m_contactsModel;

private:
    Q_DISABLE_COPY(CProfile)
    State m_state;
    Error m_error;
};

#endif // CPROFILE_H
